package Utils;

public class StringUtils {
    public static int UPPER_LOWER = 65;
    public static int UPPER_HIGHER = 90;
    public static int LOWER_LOWER = 97;
    public static int LOWER_HIGHER = 122;
    public static void main(String[] args) {
        String str = generateRandomStr(25);
        System.out.println(str);
        System.out.println(generateStringInStr(str, 5));
    }

    //65 ~ 90 => 'A' ~ 'Z'
    //97 ~ 122 => 'a' ~ 'z'
    //random number in n ~ m: (int)(Math.random() * (m - n + 1)) + n;
    public static String generateRandomStr(int len) {
        StringBuilder sb = new StringBuilder();
        int curChar = -1;
        double luController = -1.0;
        for(int i = 0; i < len; i++) {
            luController = Math.random();
            if(luController <= 0.5) {
                curChar = (int)(Math.random() * (LOWER_HIGHER - LOWER_LOWER + 1)) + LOWER_LOWER;
            }else {
                curChar = (int)(Math.random() * (UPPER_HIGHER - UPPER_LOWER + 1)) + UPPER_LOWER;
            }
            sb.append((char)curChar);
        }
        return sb.toString();
    }

    public static String generateStringInStr(String str, int len) {
        int N = str.length();
        StringBuilder sb = new StringBuilder();
        int segmentLen = N / len;
        int take = -1;
        for(int start = 0; start < N; start += segmentLen) {
            take = (int)(Math.random() * segmentLen) + start;
            sb.append(str.charAt(take));
        }
        return sb.toString();
    }
}
